// 前端API类型定义
// 基于swagger.json自动生成，与后端类型保持一致
// 生成时间: 2025-08-12T02:45:24.903Z


// ==================== 车辆相关 API 类型 ====================

export interface CreateCarRequest {
  name: string;                    // 车辆昵称
  category: string;                // 车辆类型 (小汽车, 电车, 摩托车, 卡车, 其他)
  brand: string;                   // 品牌
  carModel: string;                // 型号
  productionTime: number;          // 生产时间（时间戳）
  purchaseTime: number;            // 购买时间（时间戳）
  vehicleType: 'fuel' | 'electric' | 'motor';  // 车类型
  licensePlate?: string;           // 车牌号
  notes?: string;                  // 备注
  currentMileage?: number;         // 当前里程
  fuelCapacity?: number;           // 油箱容积
  fuelType?: string;               // 燃油类型 (#92, #95, #98, 电, 其他)
  purchasePrice?: number;          // 购买价格
  currency?: string;               // 货币 (CNY, USD, EUR)
  batteryCapacity?: number;        // 电池容量
  mileage?: number;                // 续航里程
}

export interface UpdateCarRequest {
  name?: string;                   // 车辆昵称
  brand?: string;                  // 品牌
  carModel?: string;               // 型号
  licensePlate?: string;           // 车牌号
  notes?: string;                  // 备注
  currentMileage?: number;         // 当前里程
  fuelCapacity?: number;           // 油箱容积
  fuelType?: string;               // 燃油类型
  purchasePrice?: number;          // 购买价格
  currency?: string;               // 货币
  vehicleType?: 'fuel' | 'electric' | 'motor';  // 车类型
  batteryCapacity?: number;        // 电池容量
  mileage?: number;                // 续航里程
}

export interface GetCarsQuery {
  page?: number;                   // 页码
  limit?: number;                  // 每页数量
  category?: string;               // 车辆类型筛选
}

export interface CarResponse {
  _id: string;
  userId: string;
  name: string;
  category: string;
  brand: string;
  carModel: string;
  productionTime: number;
  purchaseTime: number;
  vehicleType: string;
  licensePlate?: string;
  notes?: string;
  currentMileage?: number;
  fuelCapacity?: number;
  fuelType?: string;
  purchasePrice?: number;
  currency?: string;
  batteryCapacity?: number;
  mileage?: number;
  createdAt: string;
  updatedAt: string;
}

export interface CreateCarResponse {
  success: boolean;
  message: string;
  data: CarResponse;
}

export interface GetCarsResponse {
  success: boolean;
  message: string;
  data: CarResponse[];
  pagination?: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
  };
}

export interface GetCarResponse {
  success: boolean;
  message: string;
  data: CarResponse;
}

export interface UpdateCarResponse {
  success: boolean;
  message: string;
  data: CarResponse;
}

export interface DeleteCarResponse {
  success: boolean;
  message: string;
}

// ==================== 费用记录相关 API 类型 ====================

export interface TFuelInfo {
  /** 表显单价 */
  showPrice: number;
  /** 实付单价 */
  actualPrice?: number;
  /** 表显金额 */
  showAmount: number;
  /** 加油量 */
  fuelAmount: number;
  /** 燃油类型 */
  fuelType?: '#92' | '#95' | '#98' | '柴油' | '电' | '其他';
  /** 优惠金额 */
  discountAmount?: number;
  /** 实付金额 */
  actualAmount?: number;
}

export interface CreateExpenseRequest {
  vehicleId: string;               // 车辆ID
  type: string;                    // 费用类型 (加油, 保养, 维修, 停车费, 年检, 保险, 罚单, 过路费, 拖车费, 洗车费, 车位费)
  mileage: number;                 // 里程数
  fuelInfo?: TFuelInfo;            // 加油信息
  isFull?: boolean;                // 邮箱是否加满
  isRecord?: boolean;              // 上次是否记录
  isWarning?: boolean;             // 油箱灯是否亮
  currency?: "CNY" | "USD" | "EUR"; // 货币
  date: string;                    // 费用日期 (YYYY-MM-DD)
  notes?: string;                  // 备注
  location?: string;               // 费用地点
  odometer?: number;               // 里程表（保留向后兼容）
  description?: string;            // 描述（保留向后兼容）
  imageUrl?: string;               // 图片URL
}

export interface UpdateExpenseRequest {
  type?: string;                   // 费用类型
  mileage?: number;                // 里程数
  fuelInfo?: TFuelInfo;            // 加油信息
  isFull?: boolean;                // 邮箱是否加满
  isRecord?: boolean;              // 上次是否记录
  isWarning?: boolean;             // 油箱灯是否亮
  currency?: "CNY" | "USD" | "EUR"; // 货币
  date?: string;                   // 费用日期
  notes?: string;                  // 备注
  location?: string;               // 费用地点
  odometer?: number;               // 里程表（保留向后兼容）
  description?: string;            // 描述（保留向后兼容）
  imageUrl?: string;               // 图片URL
}

export interface GetExpensesQuery {
  page?: number;                   // 页码
  limit?: number;                  // 每页数量
  vehicleId?: string;              // 车辆ID筛选
  type?: string;                   // 费用类型筛选
  startDate?: string;              // 开始日期
  endDate?: string;                // 结束日期
}

export interface ExpenseResponse {
  _id: string;
  userId: string;
  vehicleId: string;
  type: string;
  mileage: number;                 // 里程数
  fuelInfo?: TFuelInfo;            // 加油信息
  isFull?: boolean;                // 邮箱是否加满
  isRecord?: boolean;              // 上次是否记录
  isWarning?: boolean;             // 油箱灯是否亮
  currency?: "CNY" | "USD" | "EUR"; // 货币
  date: string;
  notes?: string;                  // 备注
  location?: string;               // 费用地点
  odometer?: number;               // 里程表（保留向后兼容）
  description?: string;            // 描述（保留向后兼容）
  imageUrl?: string;
  createdAt: string;
  updatedAt: string;
}

export interface CreateExpenseResponse {
  success: boolean;
  message: string;
  data: ExpenseResponse;
}

export interface GetExpensesResponse {
  success: boolean;
  message: string;
  data: {
    expenses: ExpenseResponse[];
    pagination: {
      page: number;
      limit: number;
      total: number;
      totalPages: number;
    };
  };
}

export interface GetExpenseResponse {
  success: boolean;
  message: string;
  data: ExpenseResponse;
}

export interface UpdateExpenseResponse {
  success: boolean;
  message: string;
  data: ExpenseResponse;
}

export interface DeleteExpenseResponse {
  success: boolean;
  message: string;
}

// ==================== 收入记录相关 API 类型 ====================

export interface CreateIncomeRequest {
  vehicleId: string;               // 车辆ID
  type: string;                    // 收入类型 (运营收入, 商业用途收入, 车辆出售, 保险理赔, 补贴与优惠, 其他)
  amount: number;                  // 收入金额
  date: string;                    // 收入日期 (YYYY-MM-DD)
  description?: string;            // 描述
}

export interface UpdateIncomeRequest {
  type?: string;                   // 收入类型
  amount?: number;                 // 收入金额
  date?: string;                   // 收入日期
  description?: string;            // 描述
}

export interface GetIncomesQuery {
  page?: number;                   // 页码
  limit?: number;                  // 每页数量
  vehicleId?: string;              // 车辆ID筛选
  type?: string;                   // 收入类型筛选
  startDate?: string;              // 开始日期
  endDate?: string;                // 结束日期
}

export interface IncomeResponse {
  _id: string;
  userId: string;
  vehicleId: string;
  type: string;
  amount: number;
  date: string;
  description?: string;
  createdAt: string;
  updatedAt: string;
}

export interface CreateIncomeResponse {
  success: boolean;
  message: string;
  data: IncomeResponse;
}

export interface GetIncomesResponse {
  success: boolean;
  message: string;
  data: IncomeResponse[];
  pagination?: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
  };
}

export interface GetIncomeResponse {
  success: boolean;
  message: string;
  data: IncomeResponse;
}

export interface UpdateIncomeResponse {
  success: boolean;
  message: string;
  data: IncomeResponse;
}

export interface DeleteIncomeResponse {
  success: boolean;
  message: string;
}

// ==================== 用户相关 API 类型 ====================

export interface RegisterRequest {
  username: string;                // 用户名
  email: string;                   // 邮箱
  password: string;                // 密码
  nickname?: string;               // 昵称
}

export interface LoginRequest {
  username: string;                // 用户名
  password: string;                // 密码
}

export interface ChangePasswordRequest {
  oldPassword: string;             // 旧密码
  newPassword: string;             // 新密码
}

export interface UpdateUserRequest {
  nickname?: string;               // 昵称
  email?: string;                  // 邮箱
}

export interface UserResponse {
  _id: string;
  username: string;
  email: string;
  nickname?: string;
  role: string;
  createdAt: string;
  updatedAt: string;
}

export interface RegisterResponse {
  success: boolean;
  message: string;
  data: UserResponse;
}

export interface LoginResponse {
  success: boolean;
  message: string;
  data: {
    user: UserResponse;
    token: string;
  };
}

export interface GetUserResponse {
  success: boolean;
  message: string;
  data: UserResponse;
}

export interface UpdateUserResponse {
  success: boolean;
  message: string;
  data: UserResponse;
}

export interface ChangePasswordResponse {
  success: boolean;
  message: string;
}

// ==================== 统计相关 API 类型 ====================

export interface GetStatisticsQuery {
  vehicleId?: string;              // 车辆ID
  startDate?: string;              // 开始日期
  endDate?: string;                // 结束日期
  period?: string;                 // 统计周期 (day, week, month, year)
}

export interface StatisticsResponse {
  period: string;
  totalExpense: number;
  totalIncome: number;
  netExpense: number;
  fuelConsumption: number;
  averageFuelConsumption: number;
  totalDistance: number;
  averageDistance: number;
  totalDiscount: number;
  expenseBreakdown: Record<string, number>;
}

export interface GetStatisticsResponse {
  success: boolean;
  message: string;
  data: StatisticsResponse;
}

// ==================== 图表相关 API 类型 ====================

export interface GetFuelTrendQuery {
  vehicleId?: string;              // 车辆ID
  startDate?: string;              // 开始日期
  endDate?: string;                // 结束日期
}

export interface GetExpenseTrendQuery {
  vehicleId?: string;              // 车辆ID
  startDate?: string;              // 开始日期
  endDate?: string;                // 结束日期
}

export interface ChartDataResponse {
  labels: string[];
  datasets: Array<{
    label: string;
    data: number[];
    backgroundColor?: string;
    borderColor?: string;
  }>;
}

export interface GetChartDataResponse {
  success: boolean;
  message: string;
  data: ChartDataResponse;
}

// ==================== 配置相关 API 类型 ====================

export interface SetSystemParamRequest {
  key: string;                     // 参数键
  value: string;                   // 参数值
  description?: string;            // 参数描述
}

export interface GetSystemParamQuery {
  key?: string;                    // 参数键
}

export interface SystemParamResponse {
  _id: string;
  key: string;
  value: string;
  description?: string;
  createdAt: string;
  updatedAt: string;
}

export interface SetSystemParamResponse {
  success: boolean;
  message: string;
  data: SystemParamResponse;
}

export interface GetSystemParamResponse {
  success: boolean;
  message: string;
  data: SystemParamResponse | SystemParamResponse[];
}

export interface GetExpenseTypesResponse {
  success: boolean;
  message: string;
  data: string[];
}

// ==================== 通用类型 ====================

export interface ErrorResponse {
  success: false;
  message: string;
  error?: string;
}

export interface SuccessResponse {
  success: true;
  message: string;
}

export interface PaginatedResponse<T> {
  success: boolean;
  message: string;
  data: T[];
  pagination: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
  };
}

// API 客户端类型
export interface ApiClient {
  // 车辆相关
  createCar: (data: CreateCarRequest) => Promise<CreateCarResponse>;
  getCars: (query?: GetCarsQuery) => Promise<GetCarsResponse>;
  getCar: (id: string) => Promise<GetCarResponse>;
  updateCar: (id: string, data: UpdateCarRequest) => Promise<UpdateCarResponse>;
  deleteCar: (id: string) => Promise<DeleteCarResponse>;
  
  // 费用记录相关
  createExpense: (data: CreateExpenseRequest) => Promise<CreateExpenseResponse>;
  getExpenses: (query?: GetExpensesQuery) => Promise<GetExpensesResponse>;
  getExpense: (id: string) => Promise<GetExpenseResponse>;
  updateExpense: (id: string, data: UpdateExpenseRequest) => Promise<UpdateExpenseResponse>;
  deleteExpense: (id: string) => Promise<DeleteExpenseResponse>;
  
  // 收入记录相关
  createIncome: (data: CreateIncomeRequest) => Promise<CreateIncomeResponse>;
  getIncomes: (query?: GetIncomesQuery) => Promise<GetIncomesResponse>;
  getIncome: (id: string) => Promise<GetIncomeResponse>;
  updateIncome: (id: string, data: UpdateIncomeRequest) => Promise<UpdateIncomeResponse>;
  deleteIncome: (id: string) => Promise<DeleteIncomeResponse>;
  
  // 用户相关
  register: (data: RegisterRequest) => Promise<RegisterResponse>;
  login: (data: LoginRequest) => Promise<LoginResponse>;
  getUser: () => Promise<GetUserResponse>;
  updateUser: (data: UpdateUserRequest) => Promise<UpdateUserResponse>;
  changePassword: (data: ChangePasswordRequest) => Promise<ChangePasswordResponse>;
  
  // 统计相关
  getStatistics: (query?: GetStatisticsQuery) => Promise<GetStatisticsResponse>;
  
  // 图表相关
  getFuelTrend: (query?: GetFuelTrendQuery) => Promise<GetChartDataResponse>;
  getExpenseTrend: (query?: GetExpenseTrendQuery) => Promise<GetChartDataResponse>;
  
  // 配置相关
  setSystemParam: (data: SetSystemParamRequest) => Promise<SetSystemParamResponse>;
  getSystemParam: (query?: GetSystemParamQuery) => Promise<GetSystemParamResponse>;
  getExpenseTypes: () => Promise<GetExpenseTypesResponse>;
}
